using MediatR;
using Microsoft.AspNetCore.Mvc;
using WMS.Domain;
using WMS.ErrorCode;
using WMS.WebApiRead.Application.Command;

namespace WMS.WebApiRead.Controllers
{
    /// <summary>
    /// 经办人信息读操作控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class HandlerInfoController : ControllerBase
    {
        private readonly IMediator mediator;
        private readonly ILogger<HandlerInfoController> logger;

        /// <summary>
        /// 构造函数，注入MediatR和日志服务
        /// </summary>
        public HandlerInfoController(IMediator mediator, ILogger<HandlerInfoController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }

        /// <summary>
        /// 查询经办人信息（不分页）
        /// </summary>
        /// <param name="warehouseDeptId">仓库部门编号（可选），传入null或不传则查询所有</param>
        /// <returns>返回经办人信息列表</returns>
        [HttpGet]
        public async Task<ApiResult<List<HandlerInfo>>> GetHandlerInfoList([FromQuery] int? warehouseDeptId)
        {
            logger.LogInformation($"开始查询经办人信息，仓库部门编号：{warehouseDeptId?.ToString() ?? "全部"}");

            return await mediator.Send(new HandlerInfoQueryCommand
            {
                WarehouseDeptId = warehouseDeptId
            });
        }
    }
}

